package com.xiaotu.spider.license.pipeline;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.MOVPublicModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.common.util.DateUtils;
import com.xiaotu.spider.APipeline;
import com.xiaotu.spider.AUrlPageProcessor;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 MOVPublicPipeline
 * @日期 2017年7月31日
 * @作者 高海军
 * @功能 电影备案发行pipeline
 */
@Component("MOVPublicPipeline")
public class MOVPublicPipeline extends APipeline
{
    @Override
    protected void doProcess(ResultItems resultItems, Task task)
    {
        MOVPublicModel tv = resultItems.get(MOVPublicModel.class.getName());
        if (tv == null)
            return;
        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.MOV_Public_YYYYMMDD);
        cacheHandler.hSet(key, tv.getLicenseNum(), tv);
        cacheHandler.setCacheTimeout(key);
        String url = resultItems.get(AUrlPageProcessor.URL_KEY);
        if (cacheHandler.hExists(Constants.DataRedisKey.MOV_Public_History.toString(), url))
            return;
        cacheHandler.hSet(Constants.DataRedisKey.MOV_Public_History.toString(), url, DateUtils
                .fomartDateToString(new Date(), DateUtils.SECONDS_FORMAT));
    }

}
